import router from "@/router/index";
import {data} from "../data.js"
// 引入 views 文件夹下所有 vue 文件
const modules = import.meta.glob("@/views/**/*.vue");

export const initRouter = ()=>{
    let list = []
    list = getFlatMenuList(data)
    // 3.添加动态路由
    list.forEach(item => {
        item.children && delete item.children;
        if (item.component && typeof item.component == "string") {
          item.component = modules["/src/views" + item.component + ".vue"];
        }
        if (item.meta.isFull) {
          router.addRoute(item );
        } else {
          console.log(item)
          router.addRoute("layout", item );
        }
      });
    console.log('yibu')
    console.log(router.options)
    
    

}
function getFlatMenuList(menuList){
    let newList = menuList;
    return newList.flatMap(item=>[item,...(item.children ? getFlatMenuList(item.children):[])])
}